<?php
	class Technology_Model extends CI_Model {
		function __construct()
		{
			parent::__construct();	
		}
		
		function lists($p=1,$limit=50)
		{
			$start = ($p-1)*50;
			$this->db->where('active', 1); 
			$this->db->order_by("date", "desc");
			$this->db->limit($limit , $start);
			$this->db->from('technology');
			$query = $this->db->get();
			return $query->result();
		}
		
		function add($input)
		{
			if($this->session->userdata('admin_logged_in') == TRUE){
				if($input['title'] != null) {
					$data = array(
						'title' => $input['title'] ,
						'detail' => $input['detail'],
						'date' => $input['date']
					); 
					$this->db->insert('technology', $data);
					return $this->db->insert_id();
				}else{
					return 0;
				}
			}else{
				return 0;
			}
		}
		
		function update($input)
		{
			if($this->session->userdata('admin_logged_in') == TRUE){
				if($input['id'] != null) {
					$data = array(
						'title' => $input['title'] ,
						'detail' => $input['detail'],
						'date' => $input['date']
					);
					$this->db->where('id', $input['id']);
					return $this->db->update('technology', $data);
				}else{
					return 0;
				}
			}else{
				return 0;
			}
		}
		
		function update_img($input)
		{
			if($this->session->userdata('admin_logged_in') == TRUE){
				if($input['id'] != null) {
					$data = array(
						'img' => $input['img'] ,
					);
					$this->db->where('id', $input['id']);
					$this->db->update('technology', $data);
					return $this->db->affected_rows();
				}else{
					return 0;
				}
			}else{
				return 0;
			}
		}
		
		function get_info($id)
		{
			$this->db->where('id', $id);
			$this->db->from('technology');
			$query = $this->db->get();
			return $query->result();
		}
		
		function get_img($input)
		{
			if($input['id'] != null) {
				$this->db->select('img');
				$this->db->where('id', $input['id']);
				$this->db->from('technology');
				$query2 = $this->db->get();
				return $query2->row();
			}else{
				return 0;
			}
		}
		
		function delete($id)
		{
			if($this->session->userdata('admin_logged_in') == TRUE){
				$this->db->where('id', $id); 
				return $this->db->delete('technology');
			}
		}
	}


/* End of file technology_model.php */
/* Location: ./application/models/admin/technology_model.php */